<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
</head>

<body>
    <div id="app">
        <h2>Vue 实现简单的留言板</h2>
        <div>
            <p v-for="(item,index) in words">{{item}} - {{index}}</p>
        </div>
        <div>
            <h2>展示留言</h2>
            <div v-for="(a,b) in list">
                <span>{{a.title}}</span>
                <button v-on:click="setItemOne(a,b)">修改</button>
                <button v-on:click="list.splice(b,1)">删除</button>
            </div>
        </div>
        <div>
            <h2>添加留言</h2>
            <input type="text" v-model="text">
            <button v-on:click="addData">提交</button>
        </div>
    </div>
    <script>
        const vm = new Vue({
            el: "#app",
            data: {
                words: ["好好学习", "天天向上", "加油", "成就自我"],
                list: [
                    { title: "情人节" },
                    { title: "元宵节" },
                    { title: "女人节" },
                    { title: "妇女节" },
                    { title: "劳动节" }
                ],
                text:"666快乐"
            },
            methods:{
                setItemOne(item,index){
                    let value = window.prompt(index,item.title);
                    console.log(value);
                    if(value){
                        this.list[index].title = value;
                    }
                },
                addData(){
                    this.list.push({
                        title:this.text
                    })
                    this.text = "";
                }
            }
        })
    </script>
</body>

</html>